package com.functest.jpwise.core;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class ValueCompatibility {
    private static final Logger logger = LoggerFactory.getLogger(ValueCompatibility.class);

    /**
     * Parameter value to be used when all other values are inapplicatble
     *
     * @param thisMatcher
     * @return
     */
    public static CompatibilityPredicate thisIs(ParameterValueMatcher thisMatcher) {
        return valuesAre(thisMatcher, null);
    }

    public static CompatibilityPredicate thatIs(ParameterValueMatcher thatMatcher) {
        return valuesAre(null, thatMatcher);
    }

    public static CompatibilityPredicate valuesAre(final ParameterValueMatcher thisMatcher, final ParameterValueMatcher thatMatcher) {
        return new CompatibilityPredicate() {
            @Override
            public boolean isCompatible(ParameterValue left, ParameterValue right) {
                boolean res = true;
                if (thisMatcher != null) {
                    res = thisMatcher.matches(left);
                }

                if ((thatMatcher != null) && res) {
                    res = thatMatcher.matches(right);
                }

//                if (!res){
//                    logger.info("Incompatible: {} and {}",left, right);
//                }
                return res;
            }
        };
    }

}
